package com.framework.tx.service.impl;

import com.framework.tx.dao.UserDao;
import com.framework.tx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
// 隔离级别：读已提交，传播行为：REQUIRED。
@Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public int updateAgeByUserIdAndAge(Integer id, Integer age) {
        return userDao.updateUserAgeByIdAndAge(id, age);
    }

    @Override
    public int updateGenderByIdAndGender(Integer id, Integer gender) {
        return userDao.updateUserGenderByIdAndGender(id, gender);
    }

    @Override
    public int updateUserByIdAndAgeAndGender(Integer id, Integer age, Integer gender) {
        userDao.updateUserAgeByIdAndAge(id, age);
        int a = 1/0;
        userDao.updateUserGenderByIdAndGender(id, gender);
        return 0;
    }
}
